package com.linkoog.devtools.type_index;

import com.intellij.util.io.DataExternalizer;
import org.jetbrains.annotations.NotNull;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ListExternalizer implements DataExternalizer<List<String>> {
    @Override
    public void save(@NotNull DataOutput out, List<String> value) throws IOException {
        out.writeInt(value.size());
        for (String s : value) {
            out.writeUTF(s);
        }
    }

    @Override
    public List<String> read(@NotNull DataInput in) throws IOException {
        int size = in.readInt();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            list.add(in.readUTF());
        }
        return list;
    }
}

